#	$OpenBSD: Makefile.bsd-wrapper,v 1.11 2014/11/30 05:54:38 brad Exp $

.include <bsd.own.mk>

BINDIR=		/usr/sbin
CHROOTDIR=	/var/unbound
USER=		_unbound

XCFLAGS=	CC="${CC}" CFLAGS="${CFLAGS} ${COPTS}" LDFLAGS="${LDFLAGS}"

CONFIGURE_OPTS_UNBOUND=	--enable-allsymbols \
			--with-ssl=/usr \
			--with-libevent=/usr \
			--with-libexpat=/usr \
			--without-pthreads \
			--without-pythonmodule \
			--with-chroot-dir=${CHROOTDIR} \
			--with-pidfile=/var/run/unbound.pid \
			--with-rootkey-file=/var/unbound/db/root.key \
			--with-conf-file=${CHROOTDIR}/etc/unbound.conf \
			--with-username=${USER} \
			--disable-shared

PROG=	unbound \
	unbound-anchor \
	unbound-checkconf \
	unbound-control \
	unbound-host

SCRIPT=	unbound-control-setup

MAN=	doc/unbound.8 \
	doc/unbound.conf.5 \
	doc/unbound-anchor.8 \
	doc/unbound-checkconf.8	\
	doc/unbound-control.8 \
	doc/unbound-host.1

all:	gnu

.ifndef NOMAN
${MANALL} ${PSALL}: ${MAN}

${MAN}:	gnu
.endif

gnu: ${.OBJDIR}/config.status
	${MAKE}

.FORCE: .IGNORE

config: .FORCE
	-rm -f ${.OBJDIR}/config.cache
	cd ${.OBJDIR} && \
		PATH="/bin:/usr/bin:/sbin:/usr/sbin" \
		${XCFLAGS} \
		sh ${.CURDIR}/configure ${CONFIGURE_OPTS_UNBOUND}

${.OBJDIR}/config.status:
	cd ${.OBJDIR} && \
		PATH="/bin:/usr/bin:/sbin:/usr/sbin" \
		${XCFLAGS} \
		sh ${.CURDIR}/configure ${CONFIGURE_OPTS_UNBOUND}

.ifdef NOMAN
maninstall:
	@echo NOMAN is set
.endif

install: maninstall
.for file in ${PROG}
	${INSTALL} ${INSTALL_COPY} ${INSTALL_STRIP} \
		-o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
		${file} ${DESTDIR}${BINDIR}
.endfor

.for file in ${SCRIPT}
	${INSTALL} ${INSTALL_COPY} \
		-o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
		${file} ${DESTDIR}${BINDIR}
.endfor

BEFOREMAN= ${.OBJDIR}/config.status
CLEANFILES+= ${MAN} dnstap/dnstap_config.h doc/example.conf doc/libunbound.3 \
		smallapp/unbound-control-setup.sh

clean cleandir:
	-@if [ -e Makefile ]; then ${MAKE} realclean; fi
	rm -f ${CLEANFILES}

depend:
	# Nothing here so far...

lint:
	# Nothing here so far...

tags:
	# Nothing here so far...

.include <bsd.obj.mk>
.include <bsd.subdir.mk>
.ifndef NOMAN
.include <bsd.man.mk>
.endif
